/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.biz.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * @author Admin
 * @website https://eladmin.vip
 * @description /
 * @date 2023-02-18
 **/
@Entity
@Data
@Table(name = "hj_message")
public class Message implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "id")
    private Integer id;

    @Column(name = "`user_id`", nullable = false)
    @NotNull
    @ApiModelProperty(value = "操作人")
    private Integer userId;

    @Column(name = "`type`", nullable = false)
    @NotNull
    @ApiModelProperty(value = "类型")
    private Integer type;//消息类型 1.报警 2.其他

    @Column(name = "`name`", nullable = false)
    @NotBlank
    @ApiModelProperty(value = "标题")
    private String name;

    @Column(name = "`url`", nullable = false)
    @NotBlank
    @ApiModelProperty(value = "跳转链接")
    private String url;

    @Column(name = "`created_at`")
    @CreationTimestamp
    @ApiModelProperty(value = "createdAt")
    private Timestamp createdAt;

    @Column(name = "`updated_at`")
    @UpdateTimestamp
    @ApiModelProperty(value = "updatedAt")
    private Timestamp updatedAt;

    @Column(name = "`is_deleted`")
    @ApiModelProperty(value = "是否删除")
    private Integer isDeleted;

    @Column(name = "`is_read`")
    @ApiModelProperty(value = "是否已读")
    private Integer isRead;

    @Column(name = "`map_id`")
    @ApiModelProperty(value = "对应消息ID")
    private Integer mapId;

    @Column(name = "`menu_id`")
    @ApiModelProperty(value = "对应子系统ID")
    private Integer menuId;

    public void copy(Message source) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
